package Demo9;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Test9 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();

        for (int i = 1; i <= 1; i++) {
            System.out.print("请输入第 " + i + " 组数据的整数个数: ");
            int n = scanner.nextInt();
            System.out.print("请输入第 " + i + " 组数据的整数范围: ");
            int range = scanner.nextInt();

            int[] array = new int[n];
            for (int j = 0; j < n; j++) {
                array[j] = random.nextInt(range);
            }

            int[] arrayForQuickSort = Arrays.copyOf(array, array.length);
            int[] arrayForMergeSort = Arrays.copyOf(array, array.length);

            System.out.println("原始数组: " + Arrays.toString(array));

            // 调用快速排序并获取统计信息
            SortingStatistics quickSortStats = SortingAlgorithms.quickSortWithStats(arrayForQuickSort);
            System.out.println("快速排序结果: " + Arrays.toString(arrayForQuickSort));
            System.out.println("快速排序统计: " + quickSortStats);

            // 调用归并排序并获取统计信息
            SortingStatistics mergeSortStats = SortingAlgorithms.mergeSortWithStats(arrayForMergeSort);
            System.out.println("归并排序结果: " + Arrays.toString(arrayForMergeSort));
            System.out.println("归并排序统计: " + mergeSortStats);

            System.out.println();
        }

        scanner.close();
    }
}